<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  var lastRemaining = function (n) {
    return n > 1 ? 2 * (Math.floor(n / 2) + 1 - lastRemaining(Math.floor(n / 2))) : 1
  };

  console.log(arr());
</script>

</html>